<%@ page import="edu.auctionmart.User" %>
<head>
	<meta name="layout" content="main" />
	<title>My Account</title>
</head>

<body>
	<div class="content">
		<h1>My Account</h1>
		<g:if test="${flash.message}">
			<div class="message">${flash.message}</div>
		</g:if>
		<g:hasErrors>
			<div class="errors">
				<g:renderErrors bean="${userInstance}" as="list" />
			</div>
		</g:hasErrors>

		<fieldset class="form">
				
			<div class="fieldcontain">
				<label for="username">
					Login Name:
				</label>
				<g:fieldValue bean="${userInstance}" id="username" field="username"/>
			</div>
			
			<div class="fieldcontain">
				<label for="userRealName">
					Full Name:
				</label>
				<g:fieldValue bean="${userInstance}" id="userRealName" field="userRealName"/>
			</div>
			
			<div class="fieldcontain">
				<label for="email">
					Email:
				</label>
				<g:fieldValue bean="${userInstance}" id="email" field="email"/>
			</div>
			
			<div class="fieldcontain">
				<label for="phoneNumber">
					Phone Number for Notifications:
				</label>
				<g:fieldValue bean="${userInstance?.profile}" id="phoneNumber" field="contactPhoneNumber"/>
			</div>
			
			<div class="fieldcontain">
				<label for="contactEmail">
					Email for Notifications:
				</label>
				<g:fieldValue bean="${userInstance?.profile}" id="contactEmail" field="contactEmail"/>
			</div>	
			
			<g:link class="edit" action="edit" id="${userInstance?.id}"><g:message code="default.button.edit.label" default="Edit" /></g:link>

			<g:if test="${userInstance?.profile?.addresses?.size() > 0}">
				<br />
				<h4>Locations</h4>	
				<g:each in="${userInstance?.profile?.addresses}" var="item">
				
					<div class="iteratedContent">
						<label for="address">Address:</label>
						<g:fieldValue bean="${item}" id="address" field="addressLine"/>
						<br />
							
						<label for="town">Town:</label>
						<g:fieldValue bean="${item}" id="town" field="town"/>
						<br />
				
						<label for="state">State:</label>
						<g:fieldValue bean="${item}" id="state" field="state"/>
						<br />
				
						<label for="zipcode">Zip Code:</label>
						<g:fieldValue bean="${item}" id="zipcode" field="zipCode"/>
						
						<br />
						<g:link controller="location" action="edit" id="${item?.id}">Edit</g:link>
					</div>
					
				</g:each>
			</g:if>		
			<g:if test="${userInstance?.profile?.addresses?.size() < 3}">
				<g:link class="location" controller="location" action="create" id="${userInstance?.id}">New Location</g:link>
			</g:if>
			
			<g:if test="${winningAuctionsList.size() > 0}">
				<br /><br />
				<h4>Items won</h4>
				<g:each in="${winningAuctionsList}" var="auction">
					<div style="margin-left:2%">
						<b>Item:</b>
						${auction.item.name}
						<br />
						
						<b>Seller username:</b>
						${auction.seller.username}
						<br />
						
						<b>Name:</b>
						${auction.seller.userRealName}
						<br />
						
						<b>Email:</b>
						${auction.seller.email}
						<br />

						<g:if test="${auction.seller.profile?.contactPhoneNumber != null}">
							<b>Phone Number</b>
							${auction.seller.profile?.contactPhoneNumber}
							<br />
						</g:if>
					</div>
						
					<h4>Address Info</h4>
					
					<div style="margin-left:2%">
						<g:if test="${auction?.seller.profile?.addresses.size() > 0}">
							<g:each in="${auction.seller.profile.addresses}" var="item">
								<b>Address:</b>
								${item.addressLine}
								<br />
								
								<b>City:</b>
								${item.town}
								<br />
								
								<b>Zipcode:</b>
								${item.zipCode}
								<br />
								
								<b>State:</b>
								${item.state}
								<br /><br />	
							</g:each>
						</g:if>
						<g:link controller="feedback" action="create" id="${auction.id}">Leave Feedback</g:link>
						<br /><br />
					</div>
				</g:each>
			</g:if>
			
			<g:if test="${sellingAuctionsList.size() > 0}">
				<br /><br />
				<h4>Items sold</h4>
				<g:each in="${sellingAuctionsList}" var="auction">
					<div style="margin-left:2%">
						<b>Item:</b>
						${auction.item.name}
						<br />
						
						<b>Winner username:</b>
						${auction.winner?.username}
						<br />
						
						<b>Name:</b>
						${auction.winner?.userRealName}
						<br />
						
						<b>Email:</b>
						${auction.winner?.email}
						<br />
						
						<g:if test="${auction.winner.profile?.contactPhoneNumber != null}">
							<b>Phone Number:</b>
							${auction.winner?.profile?.contactPhoneNumber}
							<br />
						</g:if>
					</div>
					
					<h4>Address Info</h4>	
					<div style="margin-left:2%">
						<g:if test="${auction?.winner?.profile?.addresses.size() > 0}">
							<g:each in="${auction.winner?.profile.addresses}" var="item">
								<b>Address:</b>
								${item.addressLine}
								<br />
								
								<b>City:</b>
								${item.town}
								<br />
								
								<b>Zipcode:</b>
								${item.zipCode}
								<br />
								
								<b>State:</b>
								${item.state}
								<br /><br />	
							</g:each>
						</g:if>
						<g:link controller="feedback" action="create" id="${auction.id}">Leave Feedback</g:link>
						<br /><br />
					</div>
				</g:each>
			</g:if>
			
			<div id="feedbackReceived">
				<g:render template="templateFeedbackReceived"/>
			</div>
			
			<div id="feedbackGiven">
				<g:render template="templateFeedbackGiven"/>
			</div>
		
		</fieldset>
	
			
	</div>
</body>
